//
//  RHMQCommandInfoController.m
//  RuiHeAppApp
//
//  Created by Jun on 2023/8/15.
//

#import "RHMQCommandInfoController.h"
#import "QMUILabel+LHAdd.h"
#import "SYChartTool.h"
#import "RHMQEndPointModel.h"
#import "RHMQMsgModel.h"

@interface RHMQCommandInfoController ()

@property (nonatomic ,strong) RHMQMsgModel *msgModel;

@property (nonatomic ,strong) QMUILabel *contentLab;

@end

@implementation RHMQCommandInfoController


- (instancetype)initWithMsg:(RHMQMsgModel *)model{
    self = [super init];
    if(self){
        self.msgModel = model;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setTitle:@"指令信息"];
    [self.view setBackgroundColor:CFTabViewBgColor];
    [self setupUI];
}

- (void)setupUI{
    
    UIScrollView *scroll = [[UIScrollView alloc] init];
    [self.view addSubview:scroll];
    scroll.backgroundColor = [UIColor clearColor];
    
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = [UIColor clearColor];
    [scroll addSubview:contentView];
    
    UIView *bgV = [[UIView alloc] init];
    [bgV setBackgroundColor:UIColor.whiteColor];
    [bgV.layer setCornerRadius:5];
    [contentView addSubview:bgV];
    
    _contentLab = [[QMUILabel alloc] init];
    [_contentLab setTextAlignment:NSTextAlignmentLeft];
    [_contentLab setFont:[UIFont systemFontOfSize:14]];
    [_contentLab setNumberOfLines:-1];
    [_contentLab setTextColor:kCOLOR_HEX(@"999999")];
    [bgV addSubview:_contentLab];
    
    kWeakSelf;
    [scroll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(weakSelf.view);
    }];
    
    [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_offset(15);
        make.right.bottom.mas_offset(-15);
    }];
    
    [_contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(15);
        make.right.bottom.mas_offset(-15);
        make.height.mas_equalTo(30);
    }];
    
    
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(scroll);
        make.width.mas_equalTo(scroll);
        make.height.greaterThanOrEqualTo(@0.f);//此处保证容器View高度的动态变化 大于等于0.f的高度
    }];

    
    NSString *str = [NSString stringWithFormat:@"deviceId: %@\n\nmsgType: %@\n\nsn: %@\n\ndata: %@",self.msgModel.deviceId,self.msgModel.msgType,self.msgModel.sn,self.msgModel.data];
    [_contentLab setText:str];
    CGSize size = [_contentLab getLableSizeWithMaxWidth:SCREEN_WIDTH-60];
    
    [_contentLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(size.height);
    }];
}

@end
